package com.zzx;

class WorkExperience implements Cloneable { // (1) 实现Cloneable接口
    private String workDate;
    private String company;

    public Object Clone() {
        WorkExperience obj = new WorkExperience(); // (2) 创建新实例
        obj.workDate = this.workDate;
        obj.company = this.company;
        return obj;
    }
    // 其余代码省略
}

class Resume implements Cloneable { // (3) 实现Cloneable接口
    private String name;
    private String sex;
    private String age;
    private WorkExperience work;

    public Resume(String name) {
        this.name = name;
        work = new WorkExperience();
    }

    private Resume(WorkExperience work) {
        this.work = (WorkExperience)work.Clone(); // (4) 克隆工作经历
    }

    public void SetPersonInfo(String sex, String age) {
        this.sex = sex;
        this.age = age;
    }

    public void SetWorkExperience(String workDate, String company) {
//        work.workDate = workDate;
//        work.company = company;
    }

    public Object Clone() {
        Resume obj = new Resume(this.work); // (5) 使用克隆构造函数
        obj.name = this.name;
        obj.sex = this.sex;
        obj.age = this.age;
        return obj;
    }
}

class WorkResume {
    public static void main(String[] args) {
        Resume a = new Resume("张三");
        a.SetPersonInfo("男", "29");
        a.SetWorkExperience("1998〜2000", "XXX公司");
        Resume b = (Resume)a.Clone(); // (6) 克隆简历对象
        b.SetWorkExperience("2001〜2006", "YYY公司");
    }
}